const {queryDB} = require('./db.js')

/**
 * 添加用户
 */
const testAddUser = ()=>{
    const username = 'tom'
    const password = '123'
    const age = 20
    const sex = '女'

    const sql = `INSERT INTO users (username,password,age,sex)VALUES('${username}','${password}',${age},'${sex}')`
    queryDB(sql,(results)=>{
        console.log('执行sql成功' , results);
    })
}

// testAddUser()

/**
 * 查询所有用户
 */
const testFindUsers = ()=>{
    const sql = "SELECT id,username,password,age,sex FROM users"
    queryDB(sql,(results)=>{
        console.log(results);
    })
}

// testFindUsers()

/**
 * 修改用户
 * 修改用户名为admin的用户用户密码更改为abcd
 */
const testUpdateUser = ()=>{
    const username = 'zhousir'
    const password = '123456'
    const id = 3
    const sql = `UPDATE users SET password = '${password}', username='${username}' WHERE id = ${id}`
    queryDB(sql,(result)=>{
        console.log(result);
    })
}

testUpdateUser()

/**
 * 删除用户
 * 删除用户名为jack
 */
const testDeleteUser = ()=>{
    const sql = "DELETE FROM users WHERE username = 'jack' "
    queryDB(sql,(result)=>{
        console.log(result);
        
    })
}

// testDeleteUser()
